home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Programming / C / hf^k-6.dms / in.adf / Install.run / GOLDEDDATA / developer / examples / scanner / source / include.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-11-03  |  2.6 KB  |  118 lines

  1. /* -----------------------------------------------------------------------------
  2.  
  3.   COPYIGHT
  4.  
  5.   ©1995  Dietmar  Eilert  (e-mail:  DIETMAR@TOMATE.TNG.OCHE.DE).  All  Rights
  6.   Reserved.  Code  may not be reused/reproduced without written permission of
  7.   the author.
  8.  
  9.   Dietmar Eilert
  10.   Mies-v-d-Rohe-Str.31, 52074 Aachen, Germany
  11.   E-Mail: DIETMAR@TOMATE.TNG.OCHE.DE
  12.   Tel: +49-(0)241-81665
  13.        +49-(0)2525-7776
  14.   Fax: +49-(0)241-81665
  15.  
  16.   Example: scan handler looking for include lines. Scan  handlers  are  plain
  17.   functions (LoadSeg'ed  by GED): no standard C startup code, no library calls,
  18.   one hunk.
  19.  
  20.   DICE C:
  21.  
  22.   dcc include.c -// -l0 -md -mRR -o ram:include
  23.  
  24.   ------------------------------------------------------------------------------
  25. */
  26.  
  27. #include <exec/types.h>
  28.  
  29. ULONG
  30. ScanHandlerInclude(__D0 ULONG len, __A0 char **text, __A1 ULONG *line)
  31. {
  32.     const char *version = "$VER: Include 1.3 (" __COMMODORE_DATE__ ")";
  33.  
  34.     STRPTR textPtr = *text;
  35.  
  36.     // ignore leading spaces
  37.  
  38.     while (len && (*textPtr == ' ')) {
  39.  
  40.         ++textPtr;
  41.         --len;
  42.     }
  43.  
  44.     // is the next word #include ?
  45.  
  46.     if (len > 8) {
  47.  
  48.         if ((textPtr[0] == '#') && (textPtr[1] == 'i') && (textPtr[2] == 'n') && (textPtr[3] == 'c') && (textPtr[4] == 'l') && (textPtr[5] == 'u') && (textPtr[6] == 'd') && (textPtr[7] == 'e')) {
  49.  
  50.             textPtr += 8;
  51.             len     -= 8;
  52.  
  53.             // ignore spaces before argument
  54.  
  55.             while (len && (*textPtr == ' ')) {
  56.  
  57.                 ++textPtr;
  58.                 --len;
  59.             }
  60.  
  61.             if (len) {
  62.  
  63.                 UWORD marker;
  64.  
  65.                 // determine argument delimiter
  66.  
  67.                 switch (*textPtr) {
  68.  
  69.                     case 34:
  70.  
  71.                         marker = 34;
  72.  
  73.                         ++textPtr;
  74.                         --len;
  75.  
  76.                         break;
  77.  
  78.                     case '<':
  79.  
  80.                         marker = '>';
  81.  
  82.                         ++textPtr;
  83.                         --len;
  84.  
  85.                         break;
  86.  
  87.                     default:
  88.  
  89.                         marker = FALSE;
  90.                 }
  91.  
  92.                 if (len && marker) {
  93.  
  94.                     UWORD letters = 0;
  95.  
  96.                     // result begins here (e.g. "file name" or <file name>)
  97.  
  98.                     *text = textPtr;
  99.  
  100.                     // determine agument length
  101.  
  102.                     while (--len) {
  103.  
  104.                         ++letters;
  105.                         ++textPtr;
  106.  
  107.                         if (*textPtr == marker)
  108.  
  109.                             return(letters);
  110.                     }
  111.                 }
  112.             }
  113.         }
  114.     }
  115.  
  116.     return(0);
  117. }
  118.